package com.jlastu.dlxy_androidapp.view.main;

import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;

import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.tabs.TabLayout;
import com.jlastu.dlxy_androidapp.Fragment.PendingDeliveryFragment;
import com.jlastu.dlxy_androidapp.Fragment.PendingPaymentFragment;
import com.jlastu.dlxy_androidapp.Fragment.PendingShipmentFragment;
import com.jlastu.dlxy_androidapp.Fragment.RefundFragment;
import com.jlastu.dlxy_androidapp.R;
import com.jlastu.dlxy_androidapp.adapter.OrderPagerAdapter;

import java.util.ArrayList;
import java.util.List;

//我的订单页面
public class MyOrdersActivity extends AppCompatActivity {
    @Override
    public void onConfigurationChanged(android.content.res.Configuration newConfig) {
        super.onConfigurationChanged(newConfig);

        // 检查屏幕方向是否为横屏
        if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
            Log.d("Orientation", "Landscape detected");

            // 创建并启动新的Activity
            Intent intent = new Intent(this, LandscapeActivity.class);
            startActivity(intent);

            // 可选：关闭当前Activity
            finish();
        }
    }
    private ViewPager viewPager;
    private TabLayout tabLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_orders);

        viewPager = findViewById(R.id.viewPager);
        tabLayout = findViewById(R.id.tabLayout);

        // 创建订单页面片段列表
        List<Fragment> fragmentList = new ArrayList<>();
        fragmentList.add(new PendingPaymentFragment());
        fragmentList.add(new PendingShipmentFragment());
        fragmentList.add(new PendingDeliveryFragment());
        fragmentList.add(new RefundFragment());

        // 创建订单页面标题列表
        List<String> titleList = new ArrayList<>();
        titleList.add("待付款");
        titleList.add("待发货");
        titleList.add("待收货");
        titleList.add("退款/售后");


        // 创建并设置ViewPager适配器
        OrderPagerAdapter adapter = new OrderPagerAdapter(getSupportFragmentManager(), fragmentList, titleList);
        viewPager.setAdapter(adapter);

        // 将ViewPager与选项卡绑定
        tabLayout.setupWithViewPager(viewPager);
    }
}